//
//  MYNewsHotActionDetailsVC.m
//  MuYing
//
//  Created by tbb on 2020/3/12.
//  Copyright © 2020 TBB. All rights reserved.
//

#import "MYNewsHotActionDetailsVC.h"
#import <WebKit/WebKit.h>
#import "MYDynamicCommentVC.h"
@interface MYNewsHotActionDetailsVC ()<WKUIDelegate,WKNavigationDelegate>
@property (nonatomic, strong) WKWebView * wkWebView;
@property (nonatomic, strong) MYDynamicDetailsBottonView * bottonView;
@end

@implementation MYNewsHotActionDetailsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = self.newsModel.title;
    [self.view addSubview:self.wkWebView];
    
    [self.view addSubview:self.bottonView];
    [self.bottonView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.height.mas_equalTo(49);
    }];
}

-(void)setNewsModel:(MYNewsHotModel *)newsModel {
    _newsModel = newsModel;
    [self.bottonView.commentBtn setTitle:[NSString stringWithFormat:@"%@ %@",kYQLS(@"评论"),newsModel.commentNumber] forState:(UIControlStateNormal)];
    NSURLRequest *request = [NSURLRequest requestWithURL:YQSTRINGTOURL(newsModel.url)];
    [self.wkWebView loadRequest:request];
}

#pragma mark --<WKUIDelegate,WKNavigationDelegate>
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation {
    
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {
    
}

- (void)webView:(WKWebView *)webView didFailNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
    
}
#pragma mark --<WKUIDelegate,WKNavigationDelegate> end

-(WKWebView *)wkWebView {
    if (!_wkWebView) {
        //创建网页配置对象
        WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
        //初始化
        _wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-49-Height_NavBar) configuration:config];
        // UI代理
        _wkWebView.UIDelegate = self;
        // 导航代理
        _wkWebView.navigationDelegate = self;
        // 是否允许手势左滑返回上一级, 类似导航控制的左滑返回
        _wkWebView.allowsBackForwardNavigationGestures = YES;
    }
    return _wkWebView;
}


-(MYDynamicDetailsBottonView *)bottonView {
    if (!_bottonView) {
        _bottonView = [MYDynamicDetailsBottonView viewFromXib];
        _bottonView.backgroundColor = UIColor.whiteColor;
        
        _bottonView.layer.shadowColor = HexColorA(0x000000, 0.6).CGColor;//RGB(70, 69, 69).CGColor;
        //2.设置阴影偏移范围
        _bottonView.layer.shadowOffset = CGSizeMake(0, 2);
        //3.设置阴影颜色的透明度
        _bottonView.layer.shadowOpacity = 0.5;
        
        //4.设置阴影半径
        _bottonView.layer.shadowRadius = 4;
        //5.设置阴影路径
        _bottonView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.navigationController.navigationBar.bounds].CGPath;
        _bottonView.likeBtn.hidden = YES;
        _bottonView.callBtn.hidden = YES;
        ws(self);
        [_bottonView.commentBtn addTapAction:^(id  _Nonnull sender) {
            MYDynamicCommentVC *commentVC = [MYDynamicCommentVC new];
            commentVC.isHot = YES;
            commentVC.invitationId = self.newsModel.Id;
            [weakself.navigationController pushViewController:commentVC animated:true];
        }];
    }
    return _bottonView;
}
@end
